﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace LabLibary.ExtractData
{
    public class Hytachi_911
    {
        public static List<ObjResults> ExtactData(string fileName)
        {
            string _SID = string.Empty;
            string _May = "5";
            string _MaMay = string.Empty;
            string _GiaTri = string.Empty;

            DateTime _TGTra = DateTime.Now;
            DateTime _Day = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0,0,0);

            List<ObjResults> _lstResults = new List<ObjResults>();
            ObjResults _objResults = new ObjResults();

            string result = string.Empty;

            try
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    string line = sr.ReadToEnd();
                    string[] strArrayRoot = Regex.Split(line, "3 0000000000");

                    _SID = strArrayRoot[0].Remove(0, 3).Trim();
                    if (_SID.Substring(2, 1) == "0")
                        _SID = _SID.Remove(0, 5);
                    else
                        _SID = _SID.Remove(0, 4);


                    int numOfValue = 0;
                    string strSource = strArrayRoot[1];
                    strSource = strSource.Trim();

                    numOfValue = Convert.ToInt32(strSource[0].ToString());
                    strSource = strSource.Remove(0, 1);

                    string[] strArrayValue = new string[numOfValue];
                    string[] strArray01;

                    for (int i = 0; i < numOfValue; i++)
                    {
                        strSource = strSource.Trim();
                        strArrayValue[i] = strSource.Substring(0, 8);
                        strSource = strSource.Remove(0, 8).Trim();

                        strArray01 = strArrayValue[i].Split(' ');

                        _MaMay = strArray01[0].Trim();

                        for (int j = 1; j < strArray01.Length; j++)
                        {
                            if (strArray01[j].Trim() != string.Empty)
                            {
                                _GiaTri = strArray01[j].Trim();
                            }
                        }

                        _lstResults.Add(new ObjResults(_Day, _SID, _May, _MaMay, _GiaTri, _TGTra));
                    }

                    return _lstResults;
                }
            }
            catch { }
            
            
            return null;
        }
    }
}
